import { DisposeView } from "../../../../mvc/core/DisposeView";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { EffectManager } from "../../../manager/EffectManager";
import { CareerUtil } from "../../common/util/CareerUtil";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../../common/ObjCreate";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
type int = number;
//class LadderBattlefieldCareerButton
    
    export  class LadderBattlefieldCareerButton extends DisposeView
    {
        constructor(arg1: int)
        {
            super();
            this._career = arg1;
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._career > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LadderBattlefieldCareerSelect, this._career));
            }
            return;
        }

        /* internal  */onCareerSelectHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (loc1 != this._career) 
            {
                DisplayUtil.removeMe(this._selectedBitmap);
                EffectManager.glowFilterUnReg(this._careerBitmap);
            }
            else 
            {
                this.addChild(this._selectedBitmap);
                EffectManager.glowFilterReg(this._careerBitmap);
            }
            return;
        }

        /* internal  */careerBitmap(): void
        {
            var loc1=null;
            if (this._career > 0) 
            {
                loc1 = "LadderBattlefield" + String(CareerUtil.getScecondCareerImgURL(CareerUtil.getGradeCareer(this._career)).split(".")[0]);
                this._careerBitmap.filters = [];
            }
            else 
            {
                loc1 = ImagesConst.LadderBattlefieldNoSecondCareer;
                this._careerBitmap.filters = [FilterConst.colorFilter2];
            }
            this._careerBitmap.bitmapData = GlobalClass.getBitmapData(loc1);
            return;
        }

        public get career(): int
        {
            return this._career;
        }

        /* internal  */onLoadResHandler(): void
        {
            this._selectedBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.LadderBattlefieldSelectedTxt);
            this.careerBitmap();
            return;
        }

        /* internal  */addEvents(): void
        {
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            Dispatcher.addEventListener(EventName.LadderBattlefieldCareerSelect, this.onCareerSelectHandler);
            return;
        }

        /* internal  */removeEvents(): void
        {
            this.removeEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            Dispatcher.removeEventListener(EventName.LadderBattlefieldCareerSelect, this.onCareerSelectHandler);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            this._careerBitmap = ObjCreate.createGBitmap("", 0, 0, this);
            this._selectedBitmap = ObjCreate.createGBitmap("", -10, -5);
            this.addEvents();
            LoaderHelp.addResCallBack(ResFileConst.LadderBattlefield, this.onLoadResHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            this._career = 0;
            EffectManager.glowFilterUnReg(this._careerBitmap);
            this._careerBitmap.dispose(arg1);
            this._selectedBitmap.dispose(arg1);
            this._careerBitmap = null;
            this._selectedBitmap = null;
            this.removeEvents();
            return;
        }

        /* internal */ /* var */_careerBitmap: GBitmap;

        /* internal */ /* var */_selectedBitmap: GBitmap;

        /* internal */ /* var */_career: int;
    }
